using Core.SimpleTemp.Common;
using Core.SimpleTemp.Common.PagingQuery;
using Core.SimpleTemp.Entitys;
using Core.SimpleTemp.Repositories;
using Core.Toolkit.Common;
using Core.Toolkit.Core;
using Core.Toolkit.Core.Api;
using Core.Toolkit.Core.Application;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Core.SimpleTemp.Application
{
    [AutoDi()]
    public class ZB_YearStudyNumService : BaseAppService<ZB_YearStudyNumDto, ZB_YearStudyNum , ZB_YearStudyNumRepository>
        {
        readonly ExcelHelp _excelHelp;
        public ZB_YearStudyNumService (ZB_YearStudyNumRepository repository,ExcelHelp excelHelp) : base(repository){
        _excelHelp = excelHelp;
        }



        private LoadPageOffsetModelAuto<ZB_YearStudyNum, ZB_YearStudyNumDto>
            GetLoadPageOffsetMode(PagingModel<ZB_YearStudyNumDto>
                pagingQueryModel)
                {
                var loadPageOffsetModel = this.GetLoadPageOffsetModelAuto(pagingQueryModel);
                var baseQuery = _repository.QueryBase().AsNoTracking();
                loadPageOffsetModel.QueryWhere = this.CreateQRList()

         .Add("Year","=") //
         .Add("MemberId","=") //
         .Add("MemberName","=") //
         .Add("YearTime","=") //
         .Add("Remark","=") ;//


                loadPageOffsetModel.BasqQuery = baseQuery;
                loadPageOffsetModel.Order = orderModel => orderModel.CreateTime;
                loadPageOffsetModel.Selector = model => new  ZB_YearStudyNum() {
                Id = model.Id,
Year= model.Year,//
MemberId= model.MemberId,//
MemberName= model.MemberName,//
YearTime= model.YearTime,//
Remark= model.Remark,//
                };
                return loadPageOffsetModel;
                }


                public async Task <IPageModel<ZB_YearStudyNumDto>> GetList(PagingModel<ZB_YearStudyNumDto>
                    pagingQueryModel)
                    {
                    var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                    return await base.LoadPageOffsetAsync(loadPageOffsetModel);
                    }


                    public async Task<string>
                        Export(PagingModel<ZB_YearStudyNumDto>
                            pagingQueryModel)
                            {
                            var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                            var DataList = await this.ExportDataAsync(loadPageOffsetModel);
                            var excelData = DataList.Select(model => new
                            {
model.Year,
Year_title ="",
model.MemberId,
MemberId_title ="",
model.MemberName,
MemberName_title ="",
model.YearTime,
YearTime_title ="",
model.Remark,
Remark_title ="",
                            }).ToList();




                            return _excelHelp.Create(excelData);
                            }

                            }

                            }
